﻿//FileSource.cs
//Copyright (c) 2013 StockSharp LLC, all rights reserved.
//This code module is part of StockSharp library.
//This code is licensed under the GNU GENERAL PUBLIC LICENSE Version 3.
//See the file License.txt for the license details.
//More info on: http://stocksharp.com

namespace StockSharp.Algo.History.Rts
{
	using System;
	using System.Collections.Generic;

	using Ecng.Common;

	using StockSharp.BusinessEntities;

	using LumiSoft.Net.FTP.Client;

	abstract class FileSource
	{
		protected FileSource(ISecurityStorage securityStorage, SecurityIdGenerator securityIdGenerator)
		{
			if (securityStorage == null)
				throw new ArgumentNullException("securityStorage");

			if (securityIdGenerator == null)
				throw new ArgumentNullException("securityIdGenerator");

			SecurityStorage = securityStorage;
			SecurityIdGenerator = securityIdGenerator;
			DumpFolder = string.Empty;
		}

		public SecurityIdGenerator SecurityIdGenerator { get; private set; }
		public ISecurityStorage SecurityStorage { get; private set; }

		public string DumpFolder { get; set; }

		private string _ftpDirectory;

		public string FtpDirectory
		{
			get { return _ftpDirectory; }
			set
			{
				if (value == null)
					throw new ArgumentNullException("value");

				_ftpDirectory = value;
			}
		}

		public ExchangeBoard ExchangeBoard { get; set; }

		public bool IsSystemOnly { get; set; }

		protected abstract IDictionary<Security, List<Trade>> OnGetTrades(FTP_Client client, DateTime date);

		public void ProcessTrades(IDictionary<Security, IList<Trade>> trades, FTP_Client client, DateTime date)
		{
			if (!FtpDirectory.IsEmpty())
			{
				foreach (var pair in OnGetTrades(client, date))
					trades[pair.Key] = pair.Value;
			}
		}
	}
}